package com.fy.common;

import com.github.pagehelper.PageInfo;

import java.io.Serializable;


public class Result<T> implements Serializable {private static final long serialVersionUID = -1697733640925663374L;

    
    
    
    

    private int code;
    private String msg;
    private T data;
    private Long total;

    public Result() {
    }

    public Result(int code) {
        this.code = code;
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(int code, String msg, long total, T data ) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.total = total;
    }

    public static Result ok() {
        return new Result(200, "success");
    }

    public static Result ok(String msg) {
        return new Result(200, msg);
    }

    public static <T> Result<T> ok(T data) {
        return new Result(200, "success", data);
    }

    public static <T> Result<T> ok(String msg,T data) {
        return new Result(200, msg, data  );
    }

    public static <T> Result<T> ok(long total,T data) {
        return new Result(200, "success", total, data  );
    }

    public static <T> Result<T> ok(PageInfo<T> pageInfo) {
        return new Result(200, "success", pageInfo.getTotal(), pageInfo.getList()  );
    }

    public static Result error() {
        return new Result(500, "error");
    }

    public static Result noLogin(String msg) {
        return new Result(1002,msg);
    }


    public static Result error(String msg) {
        return new Result(500, msg);
    }

    public static Result error(int code,String msg) {
        return new Result(code, msg);
    }

    public static <T> Result<T> error(String msg,T data) {
        return new Result(500, msg, data  );
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }
}